﻿using Quartz;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ThermalImagery.Comm;

namespace ThermalImagery.Task
{
    /// <summary>
    /// 清理过期图片作业
    /// </summary>
    public class ClearExpiredFileTask : IJob
    {

        public void Execute(IJobExecutionContext context)
        {
            //string path = AppDomain.CurrentDomain.BaseDirectory + "\\deletefiletest\\";
            string path = System.Windows.Forms.Application.StartupPath + "\\picture\\";
            DirectoryInfo dir = new DirectoryInfo(path);
            DirectoryInfo[] dirs = dir.GetDirectories();
            foreach (DirectoryInfo di in dirs)
            {
                if (di.CreationTime < DateTime.Now.AddDays(-GolbalVariable.SysSetup.PirtureRetentionDuration))
                {
                    FileInfo[] files = di.GetFiles();
                    foreach (FileInfo fi in files)
                    {
                        fi.Delete();
                    }
                    di.Delete();
                }
            }
        }
    }
}
